class Solution:
    def isPowerOfThree(self, n: int) -> bool:
        if n <= 0:# n负数一定不为整数
            return False
        while n > 1:
            n = n / 3
        if n != 1:
            return False
        return True
#方法二 数学看n是否是3^19次方的约数
class Solution:
    def isPowerOfThree(self, n: int) -> bool:
        return n > 0 and 1162261467 % n == 0